// #include"../TcpServer.hpp"

// /*长连接测试1：创建一个客户端持续给服务器发送数据，直到超过超时时间看看是否正常*/

// int main()
// {
//     TcpSocket cli_sock;
//     cli_sock.CreateClient("127.0.0.1",8888);
//     std::string req = "GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
//     while(1) {
//         assert(cli_sock.Send(req.c_str(), req.size()) != -1);
//         char buf[1024] = {0};
//         assert(cli_sock.Recv(buf, 1023) != -1);
//         LOG(DEBUG,"[%s]", buf);
//         sleep(3);
//     }
//     cli_sock.Close();
//     return 0;
// }

/*超时连接测试1：创建一个客户端，给服务器发送一次数据后，不动了，查看服务器是否会正常的超时关闭连接*/

#include"../httplib.hpp"
using namespace HttpLib;
// int main()
// {
//     TcpSocket cli_sock;
//     cli_sock.CreateClient("127.0.0.1",8888);
//     std::string req = "GET /hello HTTP/1.1\r\nConnection: keep-alive\r\nContent-Length: 0\r\n\r\n";
//     while(1) {
//         // assert(cli_sock.Send(req.c_str(), req.size()) != -1);
//         // char buf[1024] = {0};
//         // assert(cli_sock.Recv(buf, 1023) != -1);
//         // LOG(DEBUG,"[%s]\n", buf);
//         sleep(15);
//     }
//     cli_sock.Close();
//     return 0;
// }

/*大文件传输测试，给服务器上传一个大文件，服务器将文件保存下来，观察处理结果*/
/*
    上传的文件，和服务器保存的文件一致
*/

int main()
{
    TcpSocket cli_sock;
    cli_sock.CreateClient("127.0.0.1",8888);
    std::string req = "PUT /1234.txt HTTP/1.1\r\nConnection: keep-alive\r\n";
    std::string body;
    Util::ReadFile("./hello.txt", &body);
    req += "Content-Length: " + std::to_string(body.size()) + "\r\n\r\n";
    assert(cli_sock.Send(req.c_str(), req.size()) != -1);
    assert(cli_sock.Send(body.c_str(), body.size()) != -1);
    char buf[1024] = {0};
    assert(cli_sock.Recv(buf, 1023) != -1);
    LOG(DEBUG,"[%s]\n", buf);
    sleep(100);
    cli_sock.Close();
    return 0;
}